package com.mt.course.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.course.entity.CustomerExaminationTestLogEntity;
import com.mt.course.mapper.CustomerExaminationTestLogEntityMapper;

@Component
public class CustomerExaminationTestLogServiceModel {
    private static final org.slf4j.Logger LOGGER =
        LoggerFactory.getLogger(CustomerExaminationTestLogServiceModel.class);

    @Autowired
    private CustomerExaminationTestLogEntityMapper customerExaminationTestLogEntityMapper;

    public ServiceResult<List<CustomerExaminationTestLogEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<List<CustomerExaminationTestLogEntity>> result =
            new ServiceResult<List<CustomerExaminationTestLogEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.customerExaminationTestLogEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerExaminationTestLogServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<CustomerExaminationTestLogEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<CustomerExaminationTestLogEntity> result = new ServiceResult<CustomerExaminationTestLogEntity>();
        try {
            result.setResult(this.customerExaminationTestLogEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerExaminationTestLogServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> selectTestedSum(Map<String, Object> params) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result.setResult(this.customerExaminationTestLogEntityMapper.selectTestedSum(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerExaminationTestLogServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(CustomerExaminationTestLogEntity customerExaminationTestLogEntity) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.customerExaminationTestLogEntityMapper.insert(customerExaminationTestLogEntity);
            if (save > 0) {
                id = customerExaminationTestLogEntity.getCustomerExaminationTestLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerExaminationTestLogServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(CustomerExaminationTestLogEntity customerExaminationTestLogEntity) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.customerExaminationTestLogEntityMapper
                .updateByPrimaryKeySelective(customerExaminationTestLogEntity);
            if (save > 0) {
                id = customerExaminationTestLogEntity.getCustomerExaminationTestLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[CustomerExaminationTestLogServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer>
        updateByPrimaryKeySelective(CustomerExaminationTestLogEntity customerExaminationTestLogEntity) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.customerExaminationTestLogEntityMapper
                .updateByPrimaryKeySelective(customerExaminationTestLogEntity);
            if (save > 0) {
                id = customerExaminationTestLogEntity.getCustomerExaminationTestLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[CustomerExaminationTestLogServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer customerExaminationTestLogId) {
        Assert.notNull(this.customerExaminationTestLogEntityMapper,
            "Property 'customerExaminationTestLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.customerExaminationTestLogEntityMapper.deleteByPrimaryKey(customerExaminationTestLogId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[CustomerExaminationTestLogServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }
}
